<?php
	if (!file_exists('bmconfig.php'))
		header("Location: config.php");

    session_start(); 

    require_once 'bmconfig.php';
    require_once 'lib/common.php';
    
    if (isset($_GET["logout"]))
        unset($_SESSION[BM_AUTH]);
    
    if (isLoggedIn())
        exit(header('Location: index.php'));
    
    if (isset ($_POST["user"]) && (isset ($_POST["password"])))
    {
        $user = $_POST["user"];
        $pass = ADMIN_PASSWORD_ISMD5 ? md5($_POST["password"]) : $_POST["password"];
        
        if (($user == ADMIN_USERNAME) && ($pass == ADMIN_PASSWORD))
        {    
            unset($_SESSION[BM_LAST_ACTIVITY]);
            $_SESSION[BM_AUTH] = true;
            
            header("Location: .");
        }
        else
        {
            ?>
                <br>
                <br>
                <h3>Invalid Login: Username or password is invalid</h3>
            <?php
        }
    }  
	
	$theme = defined('ACTIVE_THEME') ? ACTIVE_THEME : 'light';
?>
<html>
<head>
<link type="text/css" href="styles/<?php echo $theme ?>/login.css" media="all" rel="stylesheet">
<link rel="shortcut icon" href="img/favicon.png" type="image/png">  
<title>bitmanager :: Login</title>
</head>
<body>   
    <center>
    <form action="login.php" method="post" enctype="multipart/form-data">
        <div id='login'>
            <div id="login_top">
                <br>
                bitmanager :: Login&nbsp;
                <br>
                <br>
            </div>     
            <div id="login_mid">
                <br>
                
                <p>
                <input id='username' name="user" type="text" value=""><br class="sep">
                <input id='password' name="password" type="password" value="">
                </p>
                
                <br>
            </div>     
            <div id="login_bot">
                <input style="margin: 5px;" value="Login" type="submit"><br>
            </div>
        </div>
    </form>
    
    <?php
    
        if (ADMIN_PASSWORD == "administrator")
            echo "<span id='warning'>Default password is 'administrator' and it should be changed from bmconfig.php</span><br>";
    
    if (isset($_GET['auto'])) :?>
    <div class='error'>
        <img src='img/delete16.png'>
        You have been logged out for being inactive for more than 10 minutes!
    </div> 
    <?php endif;?>
    <div class='warning'>
        <img src='img/information.png'>
        Cookies and javascript must be enabled at this point
    </div>
    </center>
    <?php echo getFooter(); ?>
</body>
</html>